import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Test1 {
    // 神奇数
    private static Set<Integer> set = new HashSet<>();
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        for (int i = 11; i < 100; i++) {
            if (i % 2 == 0 || i % 3 == 0 || i % 5 == 0 || i % 7 == 0) {
                continue;
            } else {
                set.add(i);
                set.add(reverseInt(i));
            }
        }
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int left = in.nextInt();
            int right = in.nextInt();
            int count = 0;
            for (int i = left; i <= right; i++) {
                if (judge(i)) {
                    count++;
                }
            }
            System.out.println(count);
        }
    }

    private static boolean judge(int n) {
        String s = n + "";
        for (int i = 0; i < s.length()-1; i++) {
            for (int j = i+1; j < s.length(); j++) {
                int num = (s.charAt(i)-'0') * 10 + (s.charAt(j)-'0');
                if (set.contains(num) || set.contains(reverseInt(num))) {
                    return true;
                }
            }
        }
        return false;
    }

    private static int reverseInt(int n) {
        int ret = 0;
        while (n > 0) {
            ret = ret * 10 + n%10;
            n /= 10;
        }
        return ret;
    }
}
